<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Assuntos extends CI_Controller {

	function __construct() {
		parent::__construct();
		if(!$this->session->userdata('disproju')){
			$this->session->sess_destroy();
			redirect('login', 'refresh');
		}
	}
	public function salvarModal(){
		
		//******************************************************
		//   PERMISSAO 
		//******************************************************
		$session_data = $this->session->userdata('disproju');
		temPermissao(array('1','2'),$session_data);
		
		$p = new Assunto();
		$p->descricao =  strtoupper($this->input->post('assunto'));
				
		if($p->save()){
			echo "OK";
		}else{
			echo $p->error->string;
		}
		
		
	}
	
	
	public function consultaAssuntoJson(){
		
		$aux = array();
		$dados = array();
		$p = new Assunto();
		$p->like('descricao', $_GET['q']);
		$assunto = $p->get();
		
		foreach($assunto as $a){
			$aux['id'] = $a->id;
			$aux['name'] = $a->descricao;
			array_push($dados,$aux);
		}
		echo json_encode($dados);
		
	
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */